﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DIT.DB.Database
{
    public static class DataReaderExtension
    {
        public static IEnumerable<IDataRecord> ReadAll(this IDataReader reader)
        {
            List<IDataRecord> recordCollection = new List<IDataRecord>();
            int rowCount = 0;
            while (reader.Read())
            {
                rowCount++;
                recordCollection.Add((IDataRecord)reader);
            }
            return rowCount == 0 ? null : recordCollection;
        }
        public static IDataRecord FirstOrDefault(this IDataReader reader)
        {
            if (reader.Read())
                return (IDataRecord)reader;
            else return null;
        }
    }
}
